package com.hzjy.manage.controller;


import com.hzjy.common.annotation.Log;
import com.hzjy.common.core.controller.BaseController;
import com.hzjy.common.core.domain.AjaxResult;
import com.hzjy.common.core.page.TableDataInfo;
import com.hzjy.common.enums.BusinessType;
import com.hzjy.common.utils.poi.ExcelUtil;
import com.hzjy.api.service.impl.LinkServiceImpl;
import com.hzjy.api.beans.Link;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 友情链接
 */

@RestController
@RequestMapping("/manage/link")
public class LinkController extends BaseController{

    @Autowired
    private LinkServiceImpl sysLinkService;

    /**
     * 查询友情链接列表
     */
    @PreAuthorize("@ss.hasPermi('manage:link:list')")
    @GetMapping("/list")
    public TableDataInfo list(Link sysLink) {
        startPage();
        List<Link> list = sysLinkService.selectSysLinkList(sysLink);
        return getDataTable(list);
    }

    /**
     * 导出友情链接列表
     */
    @PreAuthorize("@ss.hasPermi('manage:link:export')")
    @Log(title = "友情链接", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(Link sysLink) {
        List<Link> list = sysLinkService.selectSysLinkList(sysLink);
        ExcelUtil<Link> util = new ExcelUtil<Link>(Link.class);
        return util.exportExcel(list, "link");
    }

    /**
     * 获取友情链接详细信息
     */
    @PreAuthorize("@ss.hasPermi('manage:link:query')")
    @GetMapping("/selectOne")
    public AjaxResult getInfo(@PathVariable("id") Integer id) {
        return AjaxResult.success(sysLinkService.selectSysLinkById(id));
    }

    /**
     * 新增友情链接
     */
    @PreAuthorize("@ss.hasPermi('manage:link:add')")
    @PostMapping("/add")
    public AjaxResult add(@RequestBody Link sysLink) {
        return toAjax(sysLinkService.insertSysLink(sysLink));
    }

    /**
     * 修改友情链接
     */
    @PreAuthorize("@ss.hasPermi('manage:link:edit')")
    @PostMapping("/update")
    public AjaxResult edit(@RequestBody Link sysLink) {
        return toAjax(sysLinkService.updateSysLink(sysLink));
    }

    /**
     * 删除友情链接
     */
    @PreAuthorize("@ss.hasPermi('manage:link:remove')")
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Integer[] ids) {
        return toAjax(sysLinkService.deleteSysLinkByIds(ids));
    }

    /**
     * 删除友情链接
     */
    @PreAuthorize("@ss.hasPermi('manage:link:delete')")
    @PostMapping("/delete")
    public AjaxResult delete(@RequestBody Link link) {
        return toAjax(sysLinkService.deleteSysLinkById(link.getId()));
    }
}
